package main

import (
	"flag"
	"log"

	"github.com/opencloudos/onyx/internal/fetcher"
)

func main() {
	addr := flag.String("listen", ":8090", "HTTP listen address")
	cacheDir := flag.String("cache", "/var/lib/onyx/cache", "Local CAS cache directory")
	remote := flag.String("remote", "", "Remote layer base URL (required)")
	flag.Parse()

	if *remote == "" {
		log.Fatal("--remote must be specified, e.g., https://registry.example.com/v2/layers/")
	}

	server := fetcher.NewDaemon(*addr, *cacheDir, *remote)
	log.Printf("[onyx-daemon] starting on %s ...", *addr)

	if err := server.Run(); err != nil {
		log.Fatalf("daemon error: %v", err)
	}
}
